package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteUDFromService;
import com.ruoyi.system.api.domain.UDFormApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author cheng
 * @create 2021-09-06-16:27
 */
@Component
public class RemoteUDFromFallbackFactory implements FallbackFactory<RemoteUDFromService>
{
    private  static  final Logger log = LoggerFactory.getLogger(RemoteUDFromFallbackFactory.class);
    @Override
    public RemoteUDFromService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return  new RemoteUDFromService() {

            @Override
            public R<List<Map<String,Object>>> applicationList(UDFormApplication UDFormApplication) {
                return R.fail("获取当前应用失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Map<String,Object>>> webPageList(String  appId)
            {
                return R.fail("获取当前表单失败:" + throwable.getMessage());
            }

            @Override
            public R<Map<String, Object>> findById(String id, String table) {
                return R.fail("获取当前表单数据失败:" + throwable.getMessage());
            }
        };
    }
}
